home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_09_08
/
9n08084a
< prev
next >
Wrap
Text File
|
1991-07-06
|
1KB
|
51 lines
/*********** EXCEPT.C COPYRIGHT 1990 GREGORY COLVIN ************
This program may be distributed free with this copyright notice.
***************************************************************/
#include <stdio.h>
#include <string.h>
#define XDEBUG
#include "except.h"
X_TRAP *X_Trap = 0;
XCEPTION X_Error = 0;
volatile sig_atomic_t X_Signal;
char *X_Assert;
void X_TrapError( void )
{
if (X_Error) {
if (X_Trap)
longjmp(X_Trap->context,X_Error);
if (X_Error == X_ERRNO)
fprintf(stderr,"C run-time libary error: %s\n",
strerror(errno));
else if (X_Error == X_SIGNAL)
fprintf(stderr,"Signal raised: %d\n",
(int)X_Signal);
else if (X_Error == X_ASSERT)
fprintf(stderr,"Assertion false: %s\n",
X_Assert);
else if (X_Error == X_SYSTEM)
fprintf(stderr,"System call failed.\n");
else
fprintf(stderr,"Exception not handled.\n");
exit(EXIT_FAILURE);
}
}
void X_HandleSignal( int sig )
{
signal( sig, X_HandleSignal );
X_Signal = sig;
longjmp(X_Trap->context,X_SIGNAL);
}
void X_ReturnSignal( int sig )
{
signal( sig, X_ReturnSignal );
X_Signal = sig;
}